package com.kaiwukj.android.ufamily;

import androidx.annotation.NonNull;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.kaiwukj.android.ufamily.app.MyApplication;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.base.ListResp;
import com.kaiwukj.android.ufamily.mvp.http.entity.params.ActiveParams;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.ActiveResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.CommunityInfoResult;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.FriendRecoResult;
import com.kaiwukj.android.ufamily.mvp.model.HomeV20Model;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

@RunWith(AndroidJUnit4.class)
public class HomeTest {

    private HomeV20Model mModel;

    @Before
    public void init() {
        mModel = new HomeV20Model(MyApplication.getInstance().getAppComponent().repositoryManager());
    }

    @Test
    public void testFetchActive() {
        ActiveParams params = new ActiveParams();
        params.setType(1);
        params.setPageSize(10);
        params.setPage(1);
        mModel.fetchActive(params)
                .subscribe(new ApiCallBack<ListResp<ActiveResult>>() {
                    @Override
                    public void onSuccess(@NonNull ListResp<ActiveResult> result) {
                        LogUtils.d("result------------------------->" + JSON.toJSONString(result));
                    }
                });
    }

    @Test
    public void testGetActiveDetail() {
        mModel.getActiveDetail(1)
                .subscribe(new ApiCallBack<ActiveResult>() {
                    @Override
                    public void onSuccess(@NonNull ActiveResult result) {
                        LogUtils.d("result------------------------->" + JSON.toJSONString(result));
                    }
                });
    }

    @Test
    public void testFetchFriendRecoResult() {
        mModel.fetchRecoAttention(1)
                .subscribe(new ApiCallBack<List<FriendRecoResult>>() {
                    @Override
                    public void onSuccess(@NonNull List<FriendRecoResult> result) {
                        LogUtils.d("result--------------------->" + GsonUtils.toJson(result));
                    }
                });
    }

    @Test
    public void testGetCommunityInfo() {
        mModel.getCommunityInfo(1)
                .subscribe(new ApiCallBack<CommunityInfoResult>() {
                    @Override
                    public void onSuccess(@NonNull CommunityInfoResult result) {
                        System.out.println("result----------------------->" + GsonUtils.toJson(result));
                    }
                });
    }
}
